
************************************************************************;
** Output Contract Level Frequent Used Procedures and Selected Rates  **;
** For 2009 HEDIS HMO dataset                                         **;
************************************************************************;

options ls=100 nofmterr ;

libname raw '/data/Medicare_P01_2009/data/HEDIS/rawdata' ;
libname new '/data/Medicare_P01_2009/data/HEDIS/sasdata' ;
libname plan '/data/Medicare_P01_2009/data/HEDIS/plandata';


data a0; set new.hedis2009;

    **---- Exclusions ----**;

     if denom_flag=1 ;

     age = age+1; /** Set age to year end **/

     if age>=65 ;
     if state_code=' ' or state_code='00' or state_code>"53" or state_code in ("40","48") then delete;

     if age>65 and totmonth<12 then delete;

     length plantypec $ 3;

     if plan_type in ('HMO','HMO/POS','HMO/POS Combined','POS') then plantypec='HMO'; 
     if plan_type = 'PPO' then plantypec='PPO';       

     if plantypec = 'HMO' or plantypec='PPO';


     ** Total 13 plans with <500 cases, and 2 of them have <30 cases **;

     if org_id in ( 'H0838', 'H1216', 'H3240', 'H4003', 'H4004',
                    'H4006', 'H4012', 'H5577', 'H5732', 'H5774',
                    'H5821', 'H5887', 'H8991' )
     then delete;

     death_dt=bene_death_dt;
     if (bene_valid_death_dt_sw='V' or death_dt>0) then death1=1; else death1=0;

     deathyear=year(death_dt);
     deathmon=month(death_dt);

     if death1=1 and
       (deathyear=2009 or
       (deathyear=2010 and (deathmon>0 and deathmon<3)))
     then delete ;


     **-- Recode 9 or 999 to 0s --**;

     array rate bcs_d bcs_n cmc_d cmc_n1 cdc_d1 cdc_n1 cdc_d4 cdc_n4 cdc_d5 cdc_n5 gso_d gso_n;  
     do over rate; 
        if rate=9 then rate=0; 
     end;

     *-- cleaning BCS --*;

     if sex=1 or age>69 then bcs_d=.;
     if bcs_d =0 or bcs_d =. then bcs_n =.;

     *-- cleaning CMC and GSO --*;

     if cmc_d=0 then cmc_n1=.;
     if gso_d=0 then gso_n=.;

     *-- cleaning CDC ---*;

     if age>75 then do; cdc_d1=.; cdc_d4=.; cdc_d5=.; end;
     if cdc_d1=0 or cdc_d1=. then cdc_n1=.;
     if cdc_d4=0 or cdc_d4=. then cdc_n4=.;
     if cdc_d5=0 or cdc_d5=. then cdc_n5=.;

     *-- Clean up FSP variables --*;

        array fpsuti  fsp_n_cabg  fsp_n_ptca  fsp_n_cc      fsp_n_ce    fsp_n_rff   fsp_n_thr  fsp_n_tkr  fsp_n_peli
                      fsp_n_och   fsp_n_cch   fsp_n_ah      fsp_n_vh    fsp_n_pros  fsp_n_mast fsp_n_lump fsp_n_bs
                      ipu_t_acdi  ipu_t_acsdi ipu_t_acmedi  ipu_t_acdy  ipu_t_acsdy ipu_t_acmedy
                      amb_t_ov    amb_t_ed    amb_t_asp     amb_t_obsrd ;
        do over fpsuti;
           if fpsuti=999 then fpsuti=0;
        end;

        **-- Clean up Gender Related Miscoding - very low occurance --**;

        if sex=1 then do; fsp_n_ah=.; fsp_n_vh=.;  fsp_n_mast=.; fsp_n_lump=.; end;  /** female only**/
        if sex=2 then fsp_n_pros=.;   /** male only**/

 
       **-- CAP measures  John and Bruce email 6-4-2010 --**;

       if fsp_n_cabg>3 then fsp_n_cabg=3;   
       if fsp_n_ptca>4 then fsp_n_ptca=4;   
       if fsp_n_cc>4   then fsp_n_cc=4;   
     
       array fps2 fsp_n_ce   fsp_n_rff   fsp_n_thr   fsp_n_tkr   fsp_n_peli    fsp_n_och   fsp_n_cch  
                  fsp_n_ah   fsp_n_vh    fsp_n_pros  fsp_n_mast  fsp_n_lump    fsp_n_bs ;
       do over fps2; 
          if fps2>2 then fps2=2;  
       end;
 
       if ipu_t_acdi > 12 then ipu_t_acdi = 12 ;     * Total discharges set max 1 per month *;
       if ipu_t_acsdi > 12 then ipu_t_acsdi = 12 ;   * Surgery discharges *; 
       if ipu_t_acmedi > 12 then ipu_t_acmedi = 12 ; * Medical discharges *;

       if ipu_t_acdy > 365 then ipu_t_acdy = 365 ;  *Maximum possible in 12 months *;
       if ipu_t_acsdy > 365 then ipu_t_acsdy = 365 ;
       if ipu_t_acmedy > 365 then ipu_t_acmedy = 365 ;

       if amb_t_ov > 50 then amb_t_ov = 50;  * Set Total Outpatient Visits maximum 1 per week *;
       if amb_t_ed > 12 then amb_t_ed = 12;  * maximum 1 per month *;
       if amb_t_asp > 12 then amb_t_asp = 12;
       if amb_t_obsrd > 12 then amb_t_obsrd = 12;


     %let fsp = fsp_n_cabg  fsp_n_ptca fsp_n_cc   fsp_n_ce    fsp_n_rff   fsp_n_thr  fsp_n_tkr  fsp_n_peli
                fsp_n_och   fsp_n_cch  fsp_n_ah   fsp_n_vh    fsp_n_pros  fsp_n_mast fsp_n_lump fsp_n_bs ;

     %let uti = ipu_t_acdi  ipu_t_acsdi ipu_t_acmedi  ipu_t_acdy  ipu_t_acsdy ipu_t_acmedy
                amb_t_ov    amb_t_ed   amb_t_asp      amb_t_obsrd ;

     %let rate = bcs_d bcs_n cmc_d cmc_n1 gso_d gso_n cdc_d1 cdc_n1 cdc_d4 cdc_n4 cdc_d5 cdc_n5;
   
     cons = 1;

     proc freq data=a0 noprint;
          tables org_id / out=org_cnt;

     **-- Create Primary State for each Health Plan --**;

     ** Note:  Eliminated this step for HEDIS 2009 as no disk space and no need **;

  **-- Create a health plan info dataset --**;

       
  data org; set a0;

       keep org_id org_name plantypec;
       proc sort nodupkey; by org_id;

  
  **-- Output Contract Level Measures --**;


  data a; set a0;

     %let measures = fsp_n_cabg  fsp_n_ptca   fsp_n_cc      fsp_n_ce    fsp_n_rff   fsp_n_thr  fsp_n_tkr  fsp_n_peli
                     fsp_n_och   fsp_n_cch    fsp_n_ah      fsp_n_vh    fsp_n_pros  fsp_n_mast fsp_n_lump fsp_n_bs 
                     ipu_t_acdi  ipu_t_acsdi  ipu_t_acmedi  ipu_t_acdy  ipu_t_acsdy ipu_t_acmedy
                     amb_t_ov    amb_t_ed     amb_t_asp     amb_t_obsrd ;


       %macro test(grp,outmon,outdata,outplan,cnt);

             proc means data=a sum maxdec=0 nway noprint;
                  class &grp;
                  var m_months;
                  output out=&outmon sum=totmonth;

             proc means data=a n std sum maxdec=2 nway noprint;
                  class &grp;
                  var &measures ;
                  output out=&outdata n= std= sum= /autoname;

            data &outplan; merge &outmon &outdata &cnt; by &grp;

                 ***********************************************************************;
                 **  Note: Compute Contract Level Utilization Measures as             **; 
                 **        Num procedures/discharges/days/visits per 1000 member year **;
                 ***********************************************************************;

                 tot_n = count;

                 n_cabg = (fsp_n_cabg_sum/totmonth)*1000*12;  label n_cabg='CABG';
                 n_ptca = (fsp_n_ptca_sum/totmonth)*1000*12;  label n_ptca='PTCA';
                 n_cc   = (fsp_n_cc_sum/totmonth)*1000*12;    label n_cc  ='CardiacCathetherization';
                 n_ce   = (fsp_n_ce_sum/totmonth)*1000*12;    label n_ce  ='CardiacEnarterectomy';
                 n_rff  = (fsp_n_rff_sum/totmonth)*1000*12;   label n_rff ='ReductionFemurFracture';
                 n_thr  = (fsp_n_thr_sum/totmonth)*1000*12;   label n_thr ='TotalHipReplacement';
                 n_tkr  = (fsp_n_tkr_sum/totmonth)*1000*12;   label n_tkr ='TotalKneereplacement';
                 n_xli  = (fsp_n_peli_sum/totmonth)*1000*12;  label n_xli ='ExcisionLargeIntest';
                 n_oc   = (fsp_n_och_sum/totmonth)*1000*12;   label n_oc  ='OpenCholecystectomy';
                 n_clc  = (fsp_n_cch_sum/totmonth)*1000*12;   label n_clc ='ClosedCholecstectomy';
                 n_ah   = (fsp_n_ah_sum/totmonth)*1000*12;    label n_ah  ='AbdominalHysterectomy';
                 n_vh   = (fsp_n_vh_sum/totmonth)*1000*12;    label n_vh  ='VaginalHysterectomy';
                 n_p    = (fsp_n_pros_sum/totmonth)*1000*12;  label n_p   ='Prostatectomy';
                 n_mast = (fsp_n_mast_sum/totmonth)*1000*12;  label n_mast='Masterctomy' ;
                 n_lump = (fsp_n_lump_sum/totmonth)*1000*12;  label n_lump='Lumpectomy' ;
                 n_bs   = (fsp_n_bs_sum/totmonth)*1000*12;    label n_bs  ='BackSurgery';

                iptotdis   = (ipu_t_acdi_sum/totmonth)*1000*12;    label iptotdis ='InpatTotalDischarges';
                ipsurdis   = (ipu_t_acsdi_sum/totmonth)*1000*12;   label ipsurdis ='InpatSurgeryDischarges';
                ipmeddis   = (ipu_t_acmedi_sum/totmonth)*1000*12;  label ipmeddis ='InpatMedicineDischarges';

                iptotdays  = (ipu_t_acdy_sum/totmonth)*1000*12;   label iptotdays ='InpatTotalDays';
                ipsurdays  = (ipu_t_acsdy_sum/totmonth)*1000*12;  label ipsurdays ='InpatSurgeryDays';
                ipmeddays  = (ipu_t_acmedy_sum/totmonth)*1000*12; label ipmeddays ='InpatMedicineDays';

                amb_opv = (amb_t_ov_sum/totmonth)*1000*12;     label amb_opv ='OutPatientVisits';
                amb_erv = (amb_t_ed_sum/totmonth)*1000*12;     label amb_erv ='EmergencyRoomVisits';
                amb_asp = (amb_t_asp_sum/totmonth)*1000*12;    label amb_asp ='AbmSugeryProcedures';
                amb_ors = (amb_t_obsrd_sum/totmonth)*1000*12 ; label amb_ors ='ObservationRoomStays';

       %mend;

       %test(org_id,    org_mon,       org_dat,       org_util,       org_cnt);

       %macro rates(grp,outdat);

             proc means data=a(where=(bcs_d=1)) mean nway noprint;
                  class &grp;
                  var bcs_n; 
                  output out=planbcs mean=bcs;
 
             proc means data=a(where=(cmc_d=1)) mean nway noprint;
                  class &grp;
                  var cmc_n1;
                  output out=plancmc mean=cmc;

             proc means data=a(where=(cdc_d1=1)) mean nway noprint;
                  class &grp;
                  var cdc_n1;
                  output out=plancdc1 mean=cdc1;

             proc means data=a(where=(cdc_d4=1)) mean nway noprint;
                  class &grp;
                  var cdc_n4;
                  output out=plancdc3 mean=cdc3;

             proc means data=a(where=(cdc_d5=1)) mean nway noprint;
                  class &grp;
                  var cdc_n5;
                  output out=plancdc4 mean=cdc4;

            proc means data=a(where=(gso_d=1)) mean nway noprint;
                  class &grp;
                  var gso_n;
                  output out=plangso mean=gso;

       
          data &outdat; merge planbcs plancmc plancdc1 plancdc3 plancdc4 plangso; by &grp;

                 format bcs cmc cdc1 cdc3 cdc4 f8.4;

                 label bcs  ='Breast Cancer Screening 65-69';
                 label cmc  ='LDL-C Screening After AccuteCare';
                 label cdc1 ='Diabetes: HbA1cTesting';
                 label cdc3 ='Diabetes: EyeExam';
                 label cdc4 ='Diabetes: LCL-C Screening';
                 label gso  ='Glaucoma Screening';

            proc sort; by &grp;


    %mend;
 
    %rates(org_id,     org_rate);


   data orgid; merge org_util org_rate; by org_id;

        proc sort; by org_id;


   data plan.cntr2009(drop= _freq_ _type_ ); merge org orgid; by org_id;
       
       proc contents data=plan.cntr2009 varnum;

endsas;



